"use strict";
const { Model } = require("sequelize");
module.exports = (sequelize, DataTypes) => {
  class Article extends Model {
    /**
     * Helper method for defining associations.
     * This method is not a part of Sequelize lifecycle.
     * The `models/index` file will call this method automatically.
     */
    static associate(models) {
      // define association here
    }
  }
  Article.init(
    {
      title: {
        type: DataTypes.STRING,
        allowNull: false,
        validate: {
          notNull: { msg: "标题必须存在" },
          notEmpty: { msg: "标题不能为空" },
          len: { args: [2, 50], msg: "标题长度必须在2-50个字符之间" },
        },
      },
      content: DataTypes.TEXT,
      // 软删除字段
      deletedAt: {
        type: DataTypes.DATE,
      },
    },
    {
      sequelize,
      // 启用软删除功能
      paranoid: true,
      modelName: "Article",
    }
  );
  return Article;
};
